#coding:utf8

####-----------------
###  赛事预告
###----------------

from flask_restful import  Resource
from flask import request
from common import token as tken
from db_base.TournamentServer import TM
import datetime
from common.getallgametype import *
from common import app_setting,base
class EventForeshow(Resource):
	def get(self):
		## 获取赛事预告安排信息
		query = request.values
		year = query.get('year')
		month = query.get('month')
		game_id = query.get('game_id',0)
		if not year.isdigit() or not month.isdigit():
			return dict(code = 30005,msg = '数据类型错误')
		
		game_dict = dict()
		game_data = TM.getByfilter('game',dict(delete_flag = 0))
		game_names = dict()
		for _game in game_data:
			game_dict[_game.get('id')] = _game.get('icon')
			game_names[_game.get("id")] = _game.get("game_name")
		datas = TM.get_event_foreshow([year,month],game_id)
		for data in datas:
			event_type_id = data.pop('event_type_id')
			start_time = data.pop('start_time')
			game_id = data.get('game_id')
			data['icon'] =app_setting.QINIUHOST +  game_dict.get(game_id)
			data['start_hm'] = start_time.strftime('%H:%M')
			foreshow_type = data.pop('foreshow_type',None)
			data['foreshow_details'] = '小组赛' if foreshow_type ==1 else '决赛'
			data['day'] = int(start_time.strftime('%d'))
			data['event_type_name'] = GetEventType().get(event_type_id,str(event_type_id))
			data['status'] = base.deal_time_for_event_s(data.pop('apply_start_time',''),data.pop('apply_end_time','')\
				,data.pop('game_start_time',''),data.pop('game_end_time',''))
			data['event_icon'] = app_setting.QINIUHOST + data.pop('event_icon','')
			data['game_name'] = game_names.get(game_id)
			data['start_time'] = start_time.strftime("%Y-%m-%d %M:%H:%S")
		
		return dict(code =0,datas = datas)

